package demo.android.myapplication.demos.views

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import cn.android.basic.dp

/**
 * <br>createBy Gw
 * <br>createTime: 2021/7/12 14:33
 */
class CircleView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    val radius = 100.dp
    val padding = 100.dp

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val width = resolveSize((radius+padding).toInt(), widthMeasureSpec)
        val height = resolveSize((radius+padding).toInt(), heightMeasureSpec)
        setMeasuredDimension(width, height)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.drawCircle(padding+radius, padding+radius, radius, paint)
    }
}